package com.wang.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wang.mapper.TbSchemeMapper;
import com.wang.mapper.TbSicknessSchemeMapper;
import com.wang.mapper.TbTaskMapper;
import com.wang.pojo.TbScheme;
import com.wang.pojo.TbSickness;
import com.wang.pojo.TbSicknessScheme;
import com.wang.pojo.TbTask;
import com.wang.service.TbSicknessSchemeService;
import com.wang.service.TbSicknessService;
import com.wang.mapper.TbSicknessMapper;
import com.wang.utills.R;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

/**
 * 疾病
 */
@Service
public class TbSicknessServiceImpl extends ServiceImpl<TbSicknessMapper, TbSickness>
    implements TbSicknessService{

    @Resource
    private TbSicknessMapper tbSicknessMapper; //疾病

    @Resource
    private TbSchemeMapper tbSchemeMapper;  //方案

    @Resource
    private TbSicknessSchemeService tbSicknessSchemeService; //中间表-任务方案表

    @Resource
    private TbTaskMapper tbTaskMapper;  //任务表

    /**
     * mongo
     *
     * @return
     */
    @Resource
    private MongoTemplate mongoTemplate;

    @Override
    public R tbSicknesslist() {

        List<TbSickness> list=this.tbSicknessMapper.selectList(new QueryWrapper<>());
        return new R(200, "true", list);
    }

    @Override
    public R tbSicknessadd(TbSickness tbSickness) {
        tbSicknessMapper.insert(tbSickness);
        HashMap<Integer, String> hashMap = new HashMap<>();
        hashMap.put(tbSickness.getSid(), tbSickness.getSicknessdepict());
        //描述放到mongo 中  提高查询效率
        mongoTemplate.save(hashMap);
        return new R(200, "true", null);
    }

    /*
    * 疾病对应的方案及任务
    * */
    @Override
    public R schemebysid(Integer sid) {
        HashSet<TbScheme> list= tbSicknessSchemeService.getschemestasklist(sid);

        //
        return new R(200, "true", list);
    }
}




